package com.demo.test.utils;

import cn.hutool.core.util.ObjectUtil;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtils {

    private static final String YMD = "yyyy-MM-dd";
    private static final String YMD_HMS = "yyyy-MM-dd HH:mm:ss";


    public static void main(String[] args) {
        System.out.println(new Date().toString());

        SimpleDateFormat s = new SimpleDateFormat(YMD); //格式化
        String DTString = s.format(new Date());
        System.out.println(DTString);

    }


    public static String getDateStrYMD(){
        SimpleDateFormat s = new SimpleDateFormat(YMD); //格式化
        String dataDate = s.format(new Date());
        return dataDate;
    }


    public static Date getDateYMD() throws ParseException {
        SimpleDateFormat day = new SimpleDateFormat(YMD); //格式化
        Date parse = day.parse(getDateStrYMD());
        return parse;
    }

    public static Date getDateYMDHMS() throws ParseException {
        SimpleDateFormat day = new SimpleDateFormat(YMD_HMS); //格式化
        Date parse = day.parse(getDateStrYMD() + " 00:00:00");
        return parse;
    }

    public static Date getDateYMDHMSByHMS(String hms) throws ParseException {
        SimpleDateFormat day = new SimpleDateFormat(YMD_HMS); //格式化

        hms = ObjectUtil.isNotEmpty(hms) ? " " + hms : " 00:00:00";
        Date parse = day.parse(getDateStrYMD() + hms);
        return parse;
    }


}
